<?php
 
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Paginator\Adapter\Model as Paginator;


class {subFolder}Controller extends ControllerBase
{

[folder start]
    /*****************************************************
     * [tblTitle]模快
     *****************************************************/
    //获取
    public function {tblName}GetByIdAction()
    {
        $id= $this->request->getPost("id");
        if($id==0){
            //表单初始值
            $model =new {tblName}();
            $model->id=0;
            //$model->status=1;
            $this->success($model->toArray());
        }

        $model = {tblName}::findFirst("id=" . $id);
        if($model){
            $this->success($model->toArray());
        }else{
            $this->error("记录获取失败");
        }
    }
    //添加
    public function {tblName}AddAction()
    {
        if ($this->request->isPost()) {
            $post = $this->request->getPost();
            /*
			if(!$post["username"]){
                $this->error("用户名不能为空.");
            }
			*/

			$model=new {tblName}();
            if($model->id==0){
                //记录初始值
                //$model->lastLoginTime=date("Y-m-d H:i:s");
            }
            $model->assign($post);

            if ($model->save() === false) {
                $this->error($model->getMessages());
            } else {
                $this->success($model->toArray());
            }
        }
    }
    //删除
    public function  {tblName}DeleteAction()
    {
	    $id= $this->request->getPost("id");
	    if(!$id){
		    $this->error("非法的参数");
	    }
	    $model={tblName}::findFirst("id=".$id);
	    if(!$model){
		    $this->error("记录不存在");
	    }
        if($model->delete() === false){
            $this->error($model->getMessages());
        }else{
            $this->success($model->toArray());
        }
    }

    //列表查询
    public function {tblName}listAction()
    {
        if($this->request->isPost()) {
            $post= $this->request->getPost();
            //查询条件
            $str_where = "1=1";
			/*
            if(!empty($post["username"])){
                $str_where.=" and username like '%".$post["username"]."%'";
            }
			*/
            //echo $str_where;exit();
            $cond["conditions"] = $str_where;

            //统计总数用于分页
            $data["total"] = {tblName}::find($cond)->count();

            //当前页记录
            $cond["limit"] = array(
                "number" => $post["pagesize"],
                "offset" => ($post["pageindex"] - 1) * $post["pagesize"]
            );
            $cond["order"] = "id desc";
            $data['rows'] = {tblName}::find($cond);
            $this->success($data);
        }
    }

[folder end]	
}
